#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
    int arr[100000] = { 0,1 };
    int i = 2;
    for (i = 2; i < 100000; i++)
    {
        arr[i] = arr[i - 1] + arr[i - 2];
    }
    int n = 0;
    scanf("%d", &n);
    for (i = 0; i < 100000; i++)
    {
        if (n >= arr[i] && n < arr[i + 1])

        {
            break;
        }
    }
    int min = (n - arr[i] < arr[i + 1] - n) ? (n - arr[i]) : (arr[i + 1] - n);
    printf("%d", min);

    return 0;
}